@extends('admin.layouts.app')
@section('css')
        <!-- Custombox css -->
       
        <link href="{{asset('admin/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css')}}" rel="stylesheet">
         
@endsection 

@section('content')

                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">维修车辆看板</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin')}}">系统</a></li>
                                    <li><a href="{{url('zadmin/dashboard')}}">维修车辆管理</a></li>
                                    <li class="active">添加维修车辆信息</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                            <h2 class="m-t-0 header-title">添加</h2>
                            <hr/>
                             @if(session('rs') || $errors->any())
                              <div class="alert alert-danger">
                        @if($errors->any())
                            @foreach($errors->messages() as $msg )
                                {{$msg[0]}}
                            @endforeach
                        @endif
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
                        			<div class="row">
			                        	<div class="col-md-12">
                                  <form method="post" action="{{url('zadmin/dashboard')}}" enctype="multipart/form-data">
                            {{ csrf_field()}}
                            <div class="row">
                               
                              <div class="row">
                                        <div class="col-md-4 form-group">
   
    <label class="col-md-4">车牌<span class="text-danger">*</span></label>
    <div class="col-md-8">
     <input class="form-control" name="car_num" value="{{old('car_num')}}" required=""/>
 </div>
</div>
    

    <div class="form-group col-md-4">
    <label class="col-md-4">进场日期<span class="text-danger">*</span></label>
    <div class="col-md-8">
     <input class="form-control" name="in_date" value="{{old('in_date')}}" required=""/>
 </div>
     </div>

    
</div>

                                        <div class="row">
                                            
                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">车型<span class="text-danger">*</span></label>
                    <div class="col-md-8">
                        <input name="car_model" class="form-control" value="{{old('car_model')}}" />
                        
                    </div> 
                                            </div>

                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">客户<span class="text-danger">*</span></label>
                    <div class="col-md-8">
                        <input name="customer_name" class="form-control" value="{{old('customer_name')}}" />
                        
                    </div> 
                                            </div>
                                           
                                            
                                </div>


                                <div class="row">
                                            
                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">联系人<span class="text-danger">*</span></label>
                    <div class="col-md-8">
                        <input name="contacter" class="form-control" value="{{old('contacter')}}" />
                        
                    </div> 
                                            </div>

                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">联系电话<span class="text-danger">*</span></label>
                    <div class="col-md-8">
                        <input name="mobile" class="form-control" value="{{old('mobile')}}" />
                        
                    </div> 
                                            </div>
                                           
                                            
                                </div>
                                                
                                <div class="row">  
                                 <div class="form-group col-md-4">
                                                <label class="col-md-4">位置<span class="text-danger">*</span></label>
                                                <div class="col-md-8"> 
                                                <input class="form-control" name="position" value="{{old('position')}}"  /> 
                                                </div>
                                            </div>          
                                        <div class="form-group col-md-4">
                                                <label class="col-md-4">故障信息</label>
                                                <div class="col-md-8">
                                                    <textarea class="form-control " name="contents">{{old('contents')}}</textarea>
                                                </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                            
                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">状态<span class="text-danger">*</span></label>
                    <div class="input-group col-md-8">
                        <input name="status" class="form-control" value="{{old('status')}}" />
                        
                    </div> 
                                            </div>

                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">紧急程度<span class="text-danger">*</span></label>
                    <div class="input-group col-md-8">
                        <select name="level" class="form-control" required="" >
                            <option value="">请选择</option>
                            @foreach($levelArr  as $k=>$arr)
                            <option value="{{$k}}">{{$arr}}</option>
                            @endforeach

                        </select>
                        
                    </div> 
                                            </div>
                                           
                                            
                                </div>

                          

                             

                             

                             <div class="col-lg-12">
                                <div class="panel panel-border panel-warning">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">维修负责人</h3>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="form-group col-md-6">
                                               <label class="col-md-4">负责人</label>

                                               <div class="col-md-8">
            <select class="form-control" required="" name="worker_id" >
                @foreach($workers as $w)
                    <option value="{{$w->id}}">{{$w->truename}}
                    </option>
                @endforeach   
            </select> 
                                            </div>
                                            </div>

                                            <div class="form-group col-md-6">
                                               <label class="col-md-4">是否推送</label>

                                               <div class="col-md-8">
                                                <input type="radio" name="is_push" checked="" value="1" >
                                                是
                                                <input type="radio" name="is_push"  value="0">否
                                            </div>
                                            </div>
                                           
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="col-lg-12">
                                <div class="form-group text-center">                                                
                                    <button type="submit" class="btn btn-info waves-effect waves-light">生成工单</button>
                                </div>
                            </div>                           
                        </div>




                                

                                        

                                    </div>

                                </div>


                            </div>


                            
                        
                        </form>
                                </div>
			                        	
			                        </div>

                             
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
      
    @endsection        
       

           



    
        @section('js')
       

<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js')}}"></script>
<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js')}}" charset="UTF-8"></script>
<script type="text/javascript">
$(document).ready(function () {  
    $(".serviceitem tr").find("select").select2();
    $('.departitem tr').find("select").select2();

    $(document).on('click','.btn-add',function(){
            $('.serviceitem tr').eq(0).find('select')
                                .select2("destroy").css('width','200px');
            var tr = $('.serviceitem tr').eq(0).clone();
           
            $('.serviceitem').append(tr);
            tr.find('select').select2();
            $('.serviceitem tr').eq(0).find('select').select2();
    });


    $(document).on('click','.btn-add-depart',function(){
            $('.departitem tr').eq(0).find('select')
                                .select2("destroy").css('width','200px');
            var tr = $('.departitem tr').eq(0).clone();          
         
            $('#depart').append(tr);
            tr.find('select').select2();
            $('.departitem tr').eq(0).find('select').select2();
            
            
    });
});    
    $(document).on('click','.btn-remove-service',function(){
        var tr_len = $('.serviceitem tr').length;
        if(tr_len>1) {
            $(this).parents('tr').remove();    
        }
        
    })

    
    $(document).on('click','.btn-remove-depart',function(){
        var tr_len = $('.departitem tr').length;
        if(tr_len>1) {
            $(this).parents('tr').remove();    
        }
        $(this).parents('tr').remove();
    })

    

    $('.date').datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        todayBtn: true,
        startDate: new Date()
       
    });

    $('#client_id').on('change',function(){
        var client_id = $(this).val();
        var url = "{{url('api/cars')}}";
       
        $.get(url,{'client_id':client_id},function(rs){
            if(rs.status==true) {
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt = opt+'<option value="'+v.id+'">'+v.car_num+'</option>'
                });
                $('#car_id').append(opt);
            }
        })
    });

    $(document).on('change','.service_type',function(){
        var _this = $(this);
        var type_id = _this.val();
        var url = "{{url('api/services')}}";
        $.get(url,{'type_id':type_id},function(rs){
            if(rs.status==true) {
                var service = _this.parents('tr').find('.service_id');
                service.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.price+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
    });

    $(document).on('change','.service_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price')
        //alert(price);
        _this.parents('tr').find('.service_price').val(price);
        
        
    });

    $(document).on('change','.depart_cate',function(){
        var _this = $(this);
        var cate_id = _this.val();
        var url = "{{url('api/departs')}}";
        $.get(url,{'cate_id':cate_id},function(rs){
            if(rs.status==true) {
                var depart = _this.parents('tr').find('.depart_id');
                depart.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.out_price+'" data-num="'+v.store_num+'">'+v.name+'</option>'; 
                });
                 depart.append(opt);
                
            }
        })
    });

    $(document).on('change','.depart_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price');
        var  num = _this.parents('tr').find('.depart_num').val();
        var store_num = _this.find("option:selected").data("num");
        if(store_num<5) {
            alert('库存小于5，请及时补充');
        }
        subTotal = num*price;
        _this.parents('tr').find('.total_price').val(subTotal);
        
    });

    $(document).on('click','.total_price',function(){
        var _this = $(this);
        var num   = _this.parents('tr').find('.depart_num').val();
        var price = _this.parents('tr').find('.depart_id option:selected').data("price");
        
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price*num);
    });

    $(document).on('click','.service_price',function(){
        var _this = $(this);
        
        var price = _this.parents('tr').find('.service_id option:selected').data("price");
        //alert(price);
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price);
    });
    




         

         
        </script>
@endsection
    
